package com.projectName.www.servlet;

import com.projectName.www.service.SlrServiceImpl;
import com.projectName.www.service.UserService;
import com.projectName.www.service.UserServiceImpl;
import com.projectName.www.po.Dish;
import com.projectName.www.po.Order;
import com.projectName.www.service.SlrService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/slrServlet")
public class SlrServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");

        String uid=request.getParameter("uId");
        String function = request.getParameter("function");
        if("func1".equals(function)){
            List<Dish> dishList = this.func1(uid);
            request.setAttribute("dishs",dishList);
            request.setAttribute("uid",uid);
            request.getRequestDispatcher("/dishlist.jsp").forward(request,response);

        }else if("func2".equals(function)){
            List<Order> orders = this.func2(uid);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
    //查看订单按钮
    List<Dish> func1(String uid){
        UserService us=new UserServiceImpl();
        List<Dish> dishBySlr = us.findDishBySlr(uid);
        return dishBySlr;

    }
    //查看订单
    List<Order> func2(String uid){
        SlrService slrService=new SlrServiceImpl();
        List<Order> orderlist = slrService.findOrder(uid);
        return orderlist;
    }
}